<template>
	<view class="content">
		<skeleton :loading="loading" v-if="reportList.length>0">
			<view class="center" v-for="(item,index) in reportList" :key="index">
				<view class="title">{{item.serveName}}</view>
				<view class="msg">
					<view class="left">
						<text class="nam">{{item.userName}}</text>
						<text class="sex">{{item.sex}}</text>
						<text class="age">{{item.age}}</text>
					</view>
					<view class="watch" @click="watch(item)">
						查看
					</view>
				</view>
				<view class="time">
					<text>{{item.createdAt}}</text>
				</view>
			</view>
			<view class="no" v-if="reportList.length<1">
				<image src="../../../static/none/report.png" mode=""></image>
				<view class="" style="text-align:center;">
					暂无护理报告
				</view>
			</view>
		</skeleton>
		<!-- 加载更多 h5端底部导航会遮盖住它 -->
		<view style="background: rgba(216, 216, 216, 0);" v-if="isReachBottom && reportList.length!=0"><uni-load-more
				:status="more"></uni-load-more></view>
		<!-- 返回顶部 -->
		<back-top :scrollTop='scrollTop'></back-top>
	</view>
</template>

<script>
	import backTop from '../../../components/uni-ui/back-top/back-top.vue';
	import skeleton from '@/components/common/skeleton/report-list.vue'
	import {
		selectAllNursingRecord
	} from '@/apis/nurse-report/index.js'
	import uniLoadMore from '@/components/uni-ui/uni-load-more/uni-load-more.vue';
	export default {
		data() {
			return {
				scrollTop: 0,
				//判断是否有信息 
				userId: '',
				reportList: [],
				more: 'loading', //more/loading/noMore
				isReachBottom: false,
				loading: false,
				pageNum: 1,
				pageSize: 7,
			}
		},
		onLoad() {
			this.userId = this.$store.state.userInfo.id
		},
		onShow() {
			if (this.reportList.length < 1) {
				this.pageNum = 1
				this.init()
				this.more = 'more'
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		//下拉
		onPullDownRefresh() {
			this.isReachBottom = false
			this.more = 'more';
			this.pageNum = 1,
				this.init()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		// 页面触底
		onReachBottom() {
			console.log('页面触底了---');
			if (this.more == 'noMore') return;
			this.isReachBottom = true;

			// 显示加载更多数据
			this.more = 'loading';
			this.pageNum++;
			this.init();
		},
		components: {
			uniLoadMore,
			skeleton,
			backTop
		},
		methods: {
			watch(item) {
				uni.navigateTo({
					url: '/pages/report/report-detaile/report-detaile?id=' + item.id
				})
			},
			async init() {
				// console.log('11', this.userId)
				if (this.userId) {
					let data = {
						userId: this.userId,
						pageSize: this.pageSize,
						pageNum: this.pageNum
					}
					let res = await selectAllNursingRecord(data)
					// console.log(res, '护理报告列表')
					if (res.success) {
						if (res.object.list.length > 0) {
							if (this.isReachBottom) {
								this.reportList.push(...res.object.list);
							} else {
								this.reportList = res.object.list;
							}
						} else {
							if (this.isReachBottom) {
								this.more = 'noMore';
								this.pageNum = 1;
							} else {
								this.reportList = [];
								this.isReachBottom = false;
							}
						}
					}
				}

			}
		},

	}
</script>

<style scoped lang="scss">
	.content {
		background: #FAFAFB;
		min-height: 100vh;
	}

	.center {
		height: 242rpx;
		padding: 32rpx 40rpx;
		border-top: 1rpx solid rgba(0, 0, 0, 0.1);
		background-color: #ffffff;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		box-sizing: border-box;

		.title {
			height: 50rpx;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #3E3E3E;
			line-height: 50rpx;
		}

		.msg {
			height: 60rpx;
			display: flex;
			justify-content: space-between;

			.left {
				height: 60rpx;
				line-height: 60rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #ADADAD;
				line-height: 60rpx;

				text {
					margin-right: 24rpx;
				}
			}

			.watch {
				width: 144rpx;
				height: 60rpx;
				background: #3C8EFF;
				border-radius: 30rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 60rpx;
				text-align: center;
			}
		}

		.time {
			height: 40rpx;
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #ADADAD;
			line-height: 40rpx;

			text {
				margin-right: 8rpx;
			}
		}
	}

	.no {
		height: 44rpx;
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #3E3E3E;
		line-height: 44rpx;
		text-align: center;
		padding-top: 180rpx;

		image {
			width: 442rpx;
			height: 284rpx;
			display: block;
			margin: 0 auto;
			margin-bottom: 80rpx;
		}
	}
</style>